<% @language="javascript" %>

<script type="text/javascript" language="javascript" runat="server" src="../_ScriptLibrary/json-lib/json.js"></script>
<script type="text/javascript" language="javascript" runat="server" src="../_ScriptLibrary/json-lib/json_content.js"></script>
<script type="text/javascript" language="javascript" runat="server" src="request.js"></script>

<script type="text/javascript" language="javascript" runat="server" src="../inc/db-query.js" charset="windows-1251"></script>
<script type="text/javascript" language="javascript" runat="server" src="../inc/placement.js"></script>

<script type="text/javascript" language="javascript" runat="server">
    function parseBoolean (val) {
        if ((val == "true") || (val == "TRUE"))
            return true
        else
            if ((val == "false") || (val == "FALSE"))
                return false
            else
                return undefined
    }

    //debugger

    var jsonRes, strRes,
        placement

    if (_REQ.Count > 0) {
        switch (_REQ.param("function").Item) {
            case "GetTeploPlace":
                placement = GetTeploPlace(parseInt(_REQ.param("arg1").Item), parseBoolean(_REQ.param("arg2").Item))

                jsonRes = strjson.code(placement)
                strRes = JSON.stringify(jsonRes)
                break
            case "GetTeploNumberUSDOfPlace":
                strRes = GetTeploNumberUSDOfPlace(parseInt(_REQ.param("arg1").Item))
                break
            case "GetElektroPlace":
                placement = GetElektroPlace(parseInt(_REQ.param("arg1").Item), parseBoolean(_REQ.param("arg2").Item))

                jsonRes = strjson.code(placement)
                strRes = JSON.stringify(jsonRes)
                break
            case "GetElektroNumberUSDOfPlace":
                strRes = GetElektroNumberUSDOfPlace (parseInt(_REQ.param("arg1").Item))
                break
            case "GetTeploPlaceListChannel":
                //debugger

                var place
                if (parseInt(_REQ.param("arg1").Item) == NaN)
                    place = _REQ.param("arg1").Item
                else {
                    place = GetTeploPlace(parseInt(_REQ.param("arg1").Item), true)
                }

                //strRes = GetTeploPlaceListChannel(place)
                jsonRes = GetTeploPlaceListChannel(_REQ.param("arg1").Item)
                strRes = JSON.stringify(jsonRes)
                break
            case "GetElektroPlaceListChannel":
                jsonRes = GetElektroPlaceListChannel(_REQ.param("arg1").Item)
                strRes = JSON.stringify(jsonRes)
                break
            case "innerHTMLSelectPlaceList":
                jsonRes = strjson.code(innerHTMLSelectPlaceList(_REQ.param("typeunit").Item, _REQ.param("idPlaceSel").Item, _REQ.param("placeCommomDesc").Item))
                strRes = JSON.stringify(jsonRes)
                break
            case "vyvod_name":
                //debugger

                var arVyvodName = jGetVyvodName().split(","),
                    jsonRes = {}
                for (var i = 0; i < arVyvodName.length; i++) {
                    jsonRes [i] = {}
                    jsonRes [i] = strjson.code(arVyvodName[i])
                }

                strRes = JSON.stringify(jsonRes)
                break
            default: ;
        }
        
        Response.Write(strRes)
    }
    else
        ;
</script>